package com.csw;

import java.awt.*;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2022/11/17 21:03
 */
public class Bg {
    //总积分
    static int count=0;
    //药水数量
    static int water_Num=3;
    //药水正在使用
    static Boolean water_use=false;
    //还有药水能使用
    static Boolean water_can=true;
    //关卡
    static int level=1;
    //目标得分
    int goal =level*15;
    //开始时间
    long startTime;
    //结束时间
    long endTime;
    //药水价格
    int price=(int)(Math.random()*10);
    //是否进入商店
    boolean isShop=false;
    void paintSelf(Graphics g){
        g.drawImage(GameUtils.bg, 0, 200, null);
        g.drawImage(GameUtils.bg1, 0, 0, null);

        switch (GameWin.state){
            case 0:
                drawStr(g, 80, 200, 400, "右键准备开始", Color.red);
                startTime=System.currentTimeMillis();
                break;
            case 1:
                //绘制矿工
                g.drawImage(GameUtils.peo, 310, 50, null);
                //绘制药水
                g.drawImage(GameUtils.water, 450, 40, null);
                drawStr(g, 30, 30, 150, "积分:"+count,Color.BLACK);
                drawStr(g, 30, 510, 70, "*"+water_Num, Color.BLACK);
                drawStr(g, 20, 30, 60, "第"+level+"关", Color.BLACK);
                drawStr(g, 30, 30, 110, "目标:"+goal, Color.BLACK);
                //时间组件
                endTime=System.currentTimeMillis();
                //20s倒计时
                long tim=20-(endTime-startTime)/1000;
                drawStr(g, 30, 520, 150, "时间:"+tim, Color.BLACK);
                break;
            case 2:
                g.drawImage(GameUtils.water, 300, 400, null);
                drawStr(g, 30, 300, 500, "价格"+price, Color.BLACK);
                drawStr(g, 30, 300, 550, "是否购买?", Color.BLACK);
                if (isShop){
                    count=count-price;
                    water_Num++;
                    isShop=false;
                    GameWin.state=1;
                    startTime=System.currentTimeMillis();
                }
                break;
            case 3:
                drawStr(g, 80, 250, 350, "失败", Color.red);
                drawStr(g, 80, 200, 450, "积分:"+count, Color.red);
                break;
            case 4:
                drawStr(g, 80, 250, 350, "成功", Color.red);
                drawStr(g, 80, 200, 450, "积分:"+count, Color.red);
                break;
        }


    }

    private static void drawStr(Graphics g,int size,int x,int y,String str,Color color){
        g.setColor(color);
        g.setFont(new Font("仿宋", Font.BOLD, size));
        g.drawString(str, x, y);
    }
    //t倒计时完成 f正在倒计时
    boolean gameTime(){
        long tim=(endTime- startTime)/ 1000;
        if (tim>20){
            //表示倒计时完成
            return true;
        }
        return false;
    }

    //重置元素
    void reGame(){
        //关卡数
        level=1;
        //目标得分
        goal=level*15;
        //总分
        count=0;
        //药水数量
        water_Num=3;
        water_use=false;
        water_can=true;
    }
}
